﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Tools;

namespace Punia
{
    [CommandAttribute(false)]
    public partial class alter_remote_binding : BaseForm
    {
        public alter_remote_binding()
            : base()
        {
        }

        protected override void Write()
        {
            StringBuilder sb = new StringBuilder();

            if (cbRemote.SelectedIndex > 0)
                sb.AppendLine("ALTER REMOTE SERVICE BINDING [" + cbRemote.Text + "]");
            else
                sb.AppendLine("ALTER REMOTE SERVICE BINDING []");

            if (cbUser.SelectedIndex > 0)
                sb.AppendLine("   WITH USER = " + cbUser.Text + "");
            else
                sb.AppendLine("   WITH USER = ");
            if (chAnonymous.Checked)
            {
                sb.AppendLine("   ,ANONYMOUS = ON");
            }
            else
            {
                sb.AppendLine("   ,ANONYMOUS = OFF");
            }

            tbCommand.Text = sb.ToString();
        }

        public alter_remote_binding(DbContext dbContext)
            : base(dbContext)
        {
            InitializeComponent();

            cbUser.DataSource = Utility.authorizations(dbContext);
            cbUser.DisplayMember = "Name";

            cbRemote.DataSource = Utility.remote_bindings(dbContext);
            cbRemote.DisplayMember = "Name";
        }

        private void cbRemote_SelectedIndexChanged(object sender, EventArgs e)
        {
            Write();
        }

        private void cbAuthor_SelectedIndexChanged(object sender, EventArgs e)
        {
            Write();
        }

        private void cbUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            Write();
        }

        private void tbService_TextChanged(object sender, EventArgs e)
        {
            Write();
        }

        private void chAnonymous_CheckedChanged(object sender, EventArgs e)
        {
            Write();
        }

        private void chAnonymous_CheckedChanged_1(object sender, EventArgs e)
        {
            Write();
        }
    }
}